import java.util.Scanner;

public class a015_矩陣的翻轉 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[][] array1;
		int m, n; // row(列), column(行)
		
		String output;
		
		while(sc.hasNext()) {			
			m = sc.nextInt();
			n = sc.nextInt();
			
			array1 = new int[m][n];
			
			for(int i = 0; i < m; i++) {
				sc.nextLine();
				
				for(int j = 0; j < n; j++)
					array1[i][j] = sc.nextInt();
			}

			output = "";
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < m; j++) {
					output += Integer.toString(array1[j][i]);
					
					if(j != m - 1)
						output += " ";
				}
				output += '\n';
			}
			
			System.out.println(output);
		}
	} // main
	
}